<style type="text/css">
    .navbar-nav {
        margin: 1em;
    }
</style>
<div class="top_nav">
    <div class="nav_menu">
        <nav class="" role="navigation">
            <div class="nav toggle col-md-1 col-lg-1">
                <a id="menu_toggle"><i class="fa fa-bars"></i></a>
            </div>
            <div class="top_search col-md-2 col-lg-2" style="margin-top:12px;">
                <div class="input-group">
                    <input type="text" class="form-control" style="border-radius: 5px 0px 0px 5px;padding-left: 10px;background: #f5f5f5;" id="btnSearch">
                    <span class="input-group-btn">
                        <a onclick="s()" class="btn btn-default" type="button" style="border-radius: 0px 5px 5px 0px;color:#515356;">搜索</a>
                    </span>
                </div>
            </div>
            <ul class="nav navbar-nav navbar-right">
                <li class="">
                    <a href="javascript:;" class="user-profile dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                        <% var headimgurl = '/images/img.jpg';if(userinfo.headimgurl){headimgurl= userinfo.headimgurl}%>
                        <img src="<%= headimgurl %>" alt=""><%= userinfo.truename %>
                        <span class=" fa fa-angle-down"></span>
                    </a>
                    <ul class="dropdown-menu dropdown-usermenu animated fadeInDown pull-right">
                        <li><a href="/am/updateHeadImg"><i class="fa fa-user pull-right"></i> 上传头像</a>
                        </li>
                        <li><a href="/am/pwd"><i class="fa fa-key pull-right"></i>  修改密码</a>
                        </li>
                        <li><a href="/logout"><i class="fa fa-sign-out pull-right"></i> 退出登录</a>
                        </li>
                    </ul>
                </li>
                <li role="presentation" class="dropdown" id="liTodos">
                    <a href="javascript:;" class="dropdown-toggle info-number" data-toggle="dropdown" aria-expanded="false">
                        <i class="fa fa-envelope-o"></i><span class="badge bg-green hide" id="spanTodoNum"></span>
                    </a>
                    <ul id="menu1" class="dropdown-menu list-unstyled msg_list animated fadeInDown" role="menu">
                        <li><div class="text-center"><a href="/am/todos"><strong>暂无待办事项</strong>&nbsp;<i class="fa fa-angle-right"></i></a></div></li>
                    </ul>
                </li>
                <li class="navbar-nav" style="margin-top: 18px;">
                    <span style="color: #bebcbc;letter-spacing: 0.1em;font-size:1.1em;"></span>
                </li>

            </ul>
        </nav>
    </div>
</div>
<script type="text/javascript" src="/js/timeago.js" ></script>
<script type="text/javascript" src="/js/timeago.zh-cn.js" ></script>
<script type="text/javascript">
    $(".timeago").timeago();
</script>
<script type="text/javascript">
    function s(){
        var keyword = $('#btnSearch').val();
        if(!keyword){
            return;
        }
        window.location.href = '/admin/tools/search?keyword='+keyword;
    }
</script>
<script type="text/javascript" src="/js/notify/pnotify.core.js"></script>
<script type="text/javascript" src="/js/notify/pnotify.buttons.js"></script>
<script type="text/javascript" src="/js/notify/pnotify.nonblock.js"></script>
<script type="text/javascript">
    $(function () {
        var todosNum = parseInt($('#spanTodoNum').text().trim());
        $.ajax({
            type:'post',
            url:'/admin/todos/ajax',
            data:null,
            dataType:'json',
            success:function(data){
                if(data.status){
                    if(data.resources.length>0){
                        $('#spanTodoNum').html(data.resources.length);
                        $('#spanTodoNum').removeClass('hide');
                        var htmlStr ='';
                        for (var i = 0; i < data.resources.length; i++) {
                            var d=new Date(data.resources[i].time);
                            var d1=d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate() + " " + d.getHours() + ":" + d.getMinutes();
                            htmlStr += '<li><a href="/am/todos"><span class="image"><img src="/images/img.jpg" alt="Profile Image" /></span><span><span>['+ data.resources[i].typeName +'] '+ data.resources[i].userName +'</span><span class="time"><time class="timeago" datetime="'+ d1 +'"></span></span><span class="message">'+ data.resources[i].title +'</span></a></li>';
                        }
                        htmlStr += '<li><div class="text-center"><a href="/am/todos"><strong>查看所有通知</strong><i class="fa fa-angle-right"></i></a></div></li>';
                        $('#menu1').empty();
                        $('#menu1').append(htmlStr);
                        $(".timeago").timeago();
                        var nowPage = window.location.pathname;
                        if(nowPage!=='/am/todos'){
                           new PNotify({
                                title: "待办事项",
                                type: "dark",
                                text: "您有新的待办事项，请注意查看",
                                nonblock: {
                                    nonblock: false
                                },
                                animation: "none"
                            }); 
                        }
                    }
                }
            }
        })

        function getQueryString(name) { 
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
            var r = window.location.search.substr(1).match(reg); 
            if (r != null) return decodeURI(r[2]); return null; 
        }

        var str = getQueryString('keyword');
        if(str){
            $('#btnSearch').val(str);
        }
    });
</script>